package com.test.junit_test;

import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

public class ExecutionTimeExtension implements BeforeEachCallback {

    @Override
    public void beforeEach(ExtensionContext context) {
        long startTime = System.currentTimeMillis();
        context.getStore(ExtensionContext.Namespace.GLOBAL).put("startTime", startTime);
    }

    public static void afterEach(ExtensionContext context) {
        long endTime = System.currentTimeMillis();
        long startTime = context.getStore(ExtensionContext.Namespace.GLOBAL).get("startTime", Long.class);
        System.out.println("Test took " + (endTime - startTime) + " ms");
    }
}
